<?php

namespace app\admin\controller\agent;

use app\common\controller\Backend;
use think\Config;
use think\Db;

/**
 * 表格联动
 * 点击左侧日志列表，右侧的表格数据会显示指定管理员的日志列表
 * @icon fa fa-table
 */
class Agentmanage extends Backend
{
    protected $model = null;
    protected $noNeedRight = ['table1', 'table2'];

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\agent\Robotuserlist();
        $this->view->assign("parttimeStatusList", $this->model->getParttimeStatusList());
        $this->admin_model = model('AdminLog');
        $ipList = $this->admin_model->whereTime('createtime', '-37 days')->group("ip")->column("ip,ip as aa");
        $this->view->assign("ipList", $ipList);
        //$this->model = model('AdminLog');
    }


    public function table1()
    {

        my_debug(1,'post--32');
        my_debug(1,$this->request->param());

        my_debug(1,'post--34');
        my_debug(1,$_POST);

        $search = $this->request->post();

        my_debug(1,'$search--39');
        my_debug(1,$search);

        $this->model = new \app\admin\model\agent\Robotuserlist();
        //设置过滤方法
        $this->request->filter(['strip_tags']);
        if ($this->request->isAjax()) {
            my_debug(1,'post--41');
            my_debug(1,$_POST);


            my_debug(1,'request--45');
            my_debug(1,$_REQUEST);


            my_debug(1,'post--43');
            my_debug(1,$this->request->param());
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();

            $agentId = 'ssp@qq.com';
            //爬虫机器人数
            $spider_count = $this->model->get_spider_count($agentId);

            //今日爬主播数
            $spider_anchor_count = $this->model->get_spider_anchor_count($agentId);
            //本周爬主播数
            $week_spider_anchor_count = $this->model->get_spider_anchor_count($agentId,'livestreamerNums',1);

            //今日爬VIP用户数
            $spider_vip_count = $this->model->get_spider_anchor_count($agentId,'vipuserNums');
            //本周爬VIP用户数
            $week_spider_vip_count = $this->model->get_spider_anchor_count($agentId,'vipuserNums',1);

            //今日抢宝箱金额
            $spider_box_count = $this->model->get_spider_anchor_count($agentId,'boxDiamonds');
            //本周抢宝箱金额
            $week_spider_box_count = $this->model->get_spider_anchor_count($agentId,'boxDiamonds',1);

            $total = model('AdminLog')
                ->where($where)
                ->order($sort, $order)
                ->count();

            $spider_names =['爬虫机器人数','今日爬主播数','本周爬主播数','今日爬VIP用户数','本周爬VIP用户数','今日抢宝箱金额','本周抢宝箱金额'];
            $spider_names =['spider number','Daily spider host number','weekly spider host number','今日爬VIP用户数','本周爬VIP用户数','今日抢宝箱金额','本周抢宝箱金额'];
            $spider_names =['จำนวนแมงมุม','จำนวนโฮสต์แมงมุมรายวัน','จำนวนโฮสต์สไปเดอร์รายสัปดาห์','今日爬VIP用户数','本周爬VIP用户数','今日抢宝箱金额','本周抢宝箱金额'];
            $spider_names =['Số người máy quét được','Streamer hôm nay quét được','Streamer tuần này quét được','今日爬VIP用户数','本周爬VIP用户数','今日抢宝箱金额','本周抢宝箱金额'];
            $spider_names =['رقم العنكبوت','رقم مضيف العنكبوت اليومي','رقم مضيف العنكبوت الأسبوعي','今日爬VIP用户数','本周爬VIP用户数','今日抢宝箱金额','本周抢宝箱金额'];
            $spider_vaules =[$spider_count,$spider_anchor_count,$week_spider_anchor_count,$spider_vip_count,$week_spider_vip_count,$spider_box_count,$week_spider_box_count];
            $limit = 7;
            $list = model('AdminLog')
                ->where($where)
                ->order($sort, $order)
                ->limit($offset, $limit)
                ->select();

            foreach ($list as $k=>&$v){
                $v['itemsName'] =  $spider_names[$k];
                $v['itemsValue'] = $spider_vaules[$k];

            }
            $list = collection($list)->toArray();

            $result = array("total" => $total, "rows" => $list);
            return json($result);
        }
        return $this->view->fetch('index');
    }

    public function table2()
    {

        $this->model = new \app\admin\model\agent\Robotuserlist();
        //设置过滤方法
        $this->request->filter(['strip_tags']);
        if ($this->request->isAjax()) {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();

            $agentId = 'ssp@qq.com';
            //验证机器人数
            $verify_spider_count = $this->model->get_verify_spider_count();

            //今日验证数
            $verify_livestreamer_count = $this->model->get_verify_livestreamer_data();
            //未验证主播数
            $where_sql = 'checkStatus = -1';
            $no_verify_livestreamer_count = $this->model->get_verify_livestreamer_data($where_sql);

            //今日可签约主播数
            $where_sql = 'checkStatus = 1';
            $sign_livestreamer_count = $this->model->get_verify_livestreamer_data($where_sql);

            //本周可签约主播数
            $week_sign_livestreamer_count = $this->model->get_verify_livestreamer_data($where_sql,1);

            //今日人工复检数
            $where_sql = 'grade != -1';
            $manual_reinspections_count = $this->model->get_verify_livestreamer_data($where_sql);

            //未复检主播数
            $where_sql = 'grade = -1';
            $no_manual_reinspections_count = $this->model->get_verify_livestreamer_data($where_sql);

            $total = model('AdminLog')
                ->where($where)
                ->order($sort, $order)
                ->count();
            $spider_names =['验证机器人数','今日验证数','未验证主播数','今日可签约主播数','本周可签约主播数','今日人工复检数','未复检主播数'];
            $spider_names =['verification robot number','Daily verifiied number','Unverified host number','Daily available host ','weekly available host','Today manual rechecks data','unrechecked host number'];
            $spider_names =['ตรวจสอบหมายเลขหุ่นยนต์','จำนวนตรวจสอบรายวัน','จำนวนโฮสต์ที่ไม่ได้รับการยืนยัน','จำนวนวีเจที่ชวนได้ในวันนี้','จำนวนวีเจที่ชวนได้ในสัปดาห์นี้','วันนี้ตรวจสอบข้อมูลซ้ำด้วยตนเอง','จำนวนวีเจที่ไม่ได้ตรวจสอบ'];
            $spider_names =['Số người máy lọc được','Số người máy lọc hôm nay','Số người chưa lọc','Số streamer có thể ký hôm nay','Số streamer có thể ký tuần này','Số lượng đã kiểm lại thủ công','Số người chưa được kiểm lại'];
            $spider_names =['رقم التحقق من الروبوت','رمز التحقق اليومي','رمز التحقق المرفوض','عدد المذيعين الذين تم التعاقد معاهم اليوم','عدد المذيعين الذين تم التعاقد معاهم في الأسبوع','عدد مرات التحقق اليومي اليومي','عدد مرات عدم التحقق اليومي'];
            $spider_vaules =[$verify_spider_count,$verify_livestreamer_count,$no_verify_livestreamer_count,$sign_livestreamer_count,$week_sign_livestreamer_count,$manual_reinspections_count,$no_manual_reinspections_count];
            $limit = 7;
            $list = model('AdminLog')
                ->where($where)
                ->order($sort, $order)
                ->limit($offset, $limit)
                ->select();

            foreach ($list as $k=>&$v){
                $v['itemsName'] =  $spider_names[$k];
                $v['itemsValue'] = $spider_vaules[$k];

            }
            $list = collection($list)->toArray();

            $result = array("total" => $total, "rows" => $list);
            return json($result);
        }
        return $this->view->fetch('index');
    }

    public function table3()
    {

        $this->model = new \app\admin\model\agent\Robotuserlist();
        //设置过滤方法
        $this->request->filter(['strip_tags']);
        if ($this->request->isAjax()) {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();

            $agentId = 'ssp@qq.com';
            //经纪机器人数
            $agentrobot_count = $this->model->get_agentrobot_work_data();

            //今日关注数
            $where_sql = '';
            $column='followNum';
            $agentrobot_follow_num = $this->model->get_agentrobot_work_data($where_sql,0,$column);

            //今日回关数
            $where_sql = 'isRefollow =1';
            $column='';
            $agentrobot_refollow_num = $this->model->get_agentrobot_refollow_data($where_sql,0,$column);

            //本周回关数
            $week_agentrobot_refollow_num = $this->model->get_agentrobot_refollow_data($where_sql,1,$column);


            //本月签约主播数
            $where_sql = 'signStatus = 1';
            $month_sign_livestreamer_count = $this->model->get_verify_livestreamer_data($where_sql,2);

            //签约成功率
            $where_sql = 'success_radio';
            $month_livestreamer_all_count = $this->model->get_verify_livestreamer_data($where_sql,2);
            $month_sign_livestreamer_success_radio = '0%';
            if($month_livestreamer_all_count){
                $month_sign_livestreamer_success_radio =  number_format($month_sign_livestreamer_count*100/$month_livestreamer_all_count).'%';
            }

            //优质主播签约率
            $where_sql = 'good_success_radio';
            $month_sign_good_livestreamer_count = $this->model->get_verify_livestreamer_data($where_sql,2);

            $month_sign_good_livestreamer_success_radio = '0%';
            if($month_livestreamer_all_count && $month_sign_good_livestreamer_count){
                $month_sign_good_livestreamer_success_radio =  number_format($month_sign_good_livestreamer_count*100/$month_livestreamer_all_count).'%';
            }

            $total = model('AdminLog')
                ->where($where)
                ->order($sort, $order)
                ->count();
            $spider_names =['经纪机器人数','今日关注数','今日回关数','本周回关数','本月签约主播数','签约成功率','优质主播签约率'];
            $spider_names =['Agent robot number','Daily  follower number','Number of customs returns today','Weekly follow back number','Monthly signed host number','signing successful rate','quality host signing rate'];
            $spider_names =['จำนวนหุ่นยนต์ตัวแทน','จำนวนผู้ติดตามรายวัน','今日回关数','จำนวนติดตามกลับรายสัปดาห์','จำนวนวีเจที่ได้ชวนเสร็จ','อัตราความสำเร็จในการลงนาม','อัตราการลงนามสมอคุณภาพสูง'];
            $spider_names =['Số máy Agency','Số người follow hôm nay','Hôm nay đếm lại','Số người follow tuần này','Số người follow tháng này','Tỷ lệ ký kết thành công','Tỷ lệ ký thành công streamer ưu tú'];
            $spider_names =['رقم الروبوت للوكيل','عدد المتابعين اليومي',' العودة اليوم','عدد  رد المتابعه الأسبوعي','عدد المذيعين الذين تم التعاقد معاهم شهريا','معدل نجاح التوقيع','معدل توقيع المذيع عالي الجودة'];
            $spider_vaules =[$agentrobot_count,$agentrobot_follow_num,$agentrobot_refollow_num,$week_agentrobot_refollow_num,$month_sign_livestreamer_count,$month_sign_livestreamer_success_radio,$month_sign_good_livestreamer_success_radio];
            $limit = 7;
            $list = model('AdminLog')
                ->where($where)
                ->order($sort, $order)
                ->limit($offset, $limit)
                ->select();

            foreach ($list as $k=>&$v){
                $v['itemsName'] =  $spider_names[$k];
                $v['itemsValue'] = $spider_vaules[$k];

            }
            $list = collection($list)->toArray();

            $result = array("total" => $total, "rows" => $list);
            return json($result);
        }
        return $this->view->fetch('index');
    }


}
